package dao.impl;

import java.sql.SQLException;

import org.apache.commons.dbutils.handlers.BeanHandler;

import bean.Photo;
import dao.PhotoDao;

public class PhotoDaoImpl extends BaseDao implements PhotoDao {

	@Override
	public Integer selectPhotobyid(Integer id) {
		try {
			Object query2 = query.query("select * from photo where photoid=?", id, new BeanHandler<Photo>(Photo.class));
			return Integer.parseInt(query2.toString());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

	@Override
	public Integer deletePhotobyid(Integer id) {
		try {
			return query.update("delete from photo where photoid=?", id);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

	@Override
	public Integer updatePhoto(Photo info) {
		String sql = "update photo set suozaiid=?,pictureid=?,pphototype=? where photoid=?";
		try {
			return query.update(sql, info.getSuozaiid(), info.getPictureid(), info.getPhototype());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

	@Override
	public Integer addPhoto(Photo info) {
		String sql = "insert into photo(suozaiid,pictureid,pphototype) VALUES(?,?,?)";
		try {
			return query.update(sql, info.getSuozaiid(), info.getPictureid(), info.getPhototype());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

}
